/// <reference types="wxt/browser" />
// <reference types="wxt/types" />

export default defineBackground(() => {
  console.log('Hello background!', { id: browser.runtime.id });

  // 定义消息类型
  interface DifyRequest {
    type: 'sendToDify';
    message: string;
  }

  interface DifyResponse {
    success: boolean;
    data?: any;
    error?: string;
  }

  // 定期检查更新
  function checkForUpdates() {
    browser.runtime.requestUpdateCheck().then(([status, details]) => {
      if (status === 'update_available') {
        console.log('Update available:', details.version);
      }
    });
  }

  // 每小时检查一次更新
  checkForUpdates();
  setInterval(checkForUpdates, 3600 * 1000);

  // 监听更新安装事件
  browser.runtime.onUpdateAvailable.addListener((details) => {
    console.log('Update available:', details.version);
  });
});
